package com.rose.doorto.footbathdoor.test;

import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import java.time.Duration;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author 李庆超
 * @email 1481791489@qq.com
 * @Package：com.rose.doorto.footbathdoor.test
 * @Project：door-to-door
 * @name：TimeIntervals
 * @date 2024/08/05 2024/8/5:10:23:
 */
@SpringBootTest
public class TimeIntervals {

    @Test
    public void getTimeIntervals(){
        LocalDateTime nowTime = LocalDateTime.now();  //当前时间
        Duration halfHour = Duration.ofMinutes(30);
        LocalDateTime minus = nowTime.plus(halfHour);//.minus(halfHour);   //半小时后的时间
        LocalDateTime endTime = minus.plusHours(8); // 假设时间区间是2小时


        List<LocalDateTime> intervals = new ArrayList<>();
        while (minus.isBefore(endTime)) {
            intervals.add(minus);
            minus = minus.plus(halfHour);
        }

        // 打印时间区间
        for (LocalDateTime interval : intervals) {
            System.out.println(interval);
        }
    }
}
